<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions 
 * @package    Socialengineaddon
 * @copyright  Copyright 2009-2010 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Core.php (var) 2010-11-18 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */

class Socialengineaddon_Api_Core extends Core_Api_Abstract {
	/**
	 *
	 * @param $title: String which are require for truncate
	 * @return string
	 */
	public function seaddonstruncateTitle($title) {
		$tmpBody = strip_tags ( $title );
		return (Engine_String::strlen ( $tmpBody ) > 13 ? Engine_String::substr ( $tmpBody, 0, 15 ) . '..' : $tmpBody);
	}
	
	public function getDefault() {
		Engine_Api::_ ()->getApi ( 'settings', 'socialengineaddon' )->getSettings ( Zend_Controller_Front::getInstance () );
	}
	
	// return: CDN enabled or not at the site.
	public function isCdn() {
		$storagemodule = Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->getModule ( 'storage' );
		$storageversion = $storagemodule->version;
		
		$db = Engine_Db_Table::getDefaultAdapter ();
		// $type_array = $db->query("SHOW COLUMNS FROM engine4_storage_servicetypes LIKE 'enabled'")->fetch();
		$cdn_path = null;
		
		if ($storageversion >= '4.1.6') {
			$storageServiceTypeTable = Engine_Api::_ ()->getDbtable ( 'serviceTypes', 'storage' );
			$storageServiceTypeTableName = $storageServiceTypeTable->info ( 'name' );
			
			$storageServiceTable = Engine_Api::_ ()->getDbtable ( 'services', 'storage' );
			$storageServiceTableName = $storageServiceTable->info ( 'name' );
			
			$select = $storageServiceTypeTable->select ()->setIntegrityCheck ( false )->from ( $storageServiceTypeTableName, array (null ) )->join ( $storageServiceTableName, "$storageServiceTypeTableName.servicetype_id = $storageServiceTableName.servicetype_id", array ('enabled', 'config', 'default' ) )->where ( "$storageServiceTypeTableName.plugin != ?", "Storage_Service_Local" )->where ( "$storageServiceTypeTableName.enabled = ?", 1 );
			
			$storageCheck = $storageServiceTypeTable->fetchRow ( $select );
			if (! empty ( $storageCheck )) {
				if ($storageCheck->enabled == 1 && $storageCheck->default == 1) {
					$cdn_path = true;
				}
			}
		}
		return $cdn_path;
	}
}
?>